{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# strtok"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "string to tokens"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Hello\n",
      " World!\n",
      " My\n",
      " name\n",
      " is\n",
      " yingshaoxo!\n"
     ]
    }
   ],
   "source": [
    "#include<stdio.h>\n",
    "#include <string.h>\n",
    "\n",
    "char string[50] = \"Hello World! My name is yingshaoxo!\";\n",
    "// Extract the first token\n",
    "char * token = strtok(string, \" \");\n",
    "// loop through the string to extract all other tokens\n",
    "while( token != NULL ) {\n",
    "  printf( \" %s\\n\", token ); //printing each token\n",
    "  token = strtok(NULL, \" \");\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`strtok` maintains a static, internal reference pointing to the next available token in the string; if you pass it a NULL pointer, it will work from that internal reference.\n",
    "\n",
    "This is the reason strtok isn't re-entrant; as soon as you pass it a new pointer as the first argument, that old internal reference gets clobbered."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
